﻿using System;
using System.Xml;
using System.Xml.Schema;
using System.Xml.Serialization;

using advadev.DataStorage;


namespace advadev.DataStorage.UnitTests
{

    /// <summary>
    /// Represents a unserializable generic test object
    /// </summary>
    public class UnserializableGenericTestObject : IGenericObject, IXmlSerializable
    {

        /// <summary>
        /// Initializes a new instance of the UnserializableGenericTestObject
        /// class
        /// </summary>
        public UnserializableGenericTestObject()
        {
        }

        /// <summary>
        /// Initializes a new instance of the UnserializableGenericTestObject
        /// class by the given parameter
        /// </summary>
        /// <param name="id">
        /// Id
        /// </param>
        /// <param name="name">
        /// Name
        /// </param>
        public UnserializableGenericTestObject(int id, string name)
        {
            Id = id;
            Name = name;
        }


        /// <summary>
        /// Gets the id
        /// </summary>
        public int Id
        {
            get;
            private set;
        }

        /// <summary>
        /// Gets the name
        /// </summary>
        public string Name
        {
            get;
            set;
        }


        #region IGenericObject Members
        /// <summary>
        /// Gets the (unique) id of the generic object
        /// </summary>
        string IGenericObject.GenericObjectId
        {
            get
            {
                return Id.ToString();
            }
        }
        #endregion


        #region IXmlSerializable Members
        XmlSchema IXmlSerializable.GetSchema()
        {
            return null;
        }

        void IXmlSerializable.ReadXml(XmlReader reader)
        {
            reader.Read();
            if (reader.MoveToContent() == XmlNodeType.Element && reader.LocalName == GetType().ToString())
            {
                Id = Int32.Parse(reader["Id"]);
                Name = reader["Name"];
            }
        }

        void IXmlSerializable.WriteXml(XmlWriter writer)
        {
            throw new Exception("not serializable");
        }
        #endregion

    }

}
